package com.leetcode.algorithm.y22.m09.w4;

/**
 * 1047. 删除字符串中的所有相邻重复项
 * 
 * https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/
 * 
 * @author jie.deng
 *
 */
class Question1047Solution01 {

	public String removeDuplicates(String s) {
		char[] chs = s.toCharArray();
		int len = s.length();
		int right = 0;
		int left = 0;
		while (right < len) {
			if (left > 0 && chs[left - 1] == chs[right]) {
				left--;
			} else {
				chs[left++] = chs[right];
			}
			right++;
		}
		return new String(chs, 0, left);
	}

}